package io.renren.modules.app.controller;

import io.renren.common.annotation.WebApi;
import io.renren.common.response.Response;
import io.renren.modules.app.dto.common.BoolResult;
import io.renren.modules.app.request.ListPositionReq;
import io.renren.modules.app.request.UpdateStepReq;
import io.renren.modules.app.service.ApiService;
import io.renren.modules.generator.service.PositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api")
@Api("库位信息接口")
public class PosiController {

    @Autowired
    PositionService positionService;
    @Autowired
    ApiService apiService;

    @WebApi
    @PostMapping("updateStep")
    @ApiOperation("上传操作步骤")
    public Response uploadwarehousingstep(@RequestBody UpdateStepReq request) {
        BoolResult result = apiService.updateStep(request);
        if (result.isResult()) {
            return Response.ok();
        } else {
            return Response.fail(result.getResulttext());
        }
    }

    @WebApi
    @PostMapping("getpositioncode")
    @ApiOperation("库位同步")
    public Response getpositioncode(@RequestBody ListPositionReq request) {
        Map<String, Object> queryMap = new HashMap<>();
        if (StringUtils.isNotEmpty(request.getPsCode())) {
            queryMap.put("psCode", request.getPsCode());
        }
        if (StringUtils.isNotEmpty(request.getAreaCode())) {
            queryMap.put("areaCode", request.getAreaCode());
        }
        return Response.ok(positionService.selectByMap(queryMap));
    }
}
